home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 23 / AACD 23.iso / AACD / Games / dynAMIte / Developer / E / dynabot.e < prev    next >
Text File  |  2001-06-24  |  2KB  |  112 lines

  1. MODULE  'dos/dos'
  2.  
  3. MODULE  '*dynamite'
  4.  
  5. PROC main()
  6.  
  7.   DEF done=FALSE, delay
  8.  
  9.   DEF dynasema=NIL:PTR TO dynamitesemaphore
  10.  
  11.   DEF ourplayer:PTR TO player, oldframe=0
  12.  
  13.   -> check if dynamite is running
  14.  
  15.   -> try to find the semaphore
  16.   Forbid()
  17.   IF dynasema:=FindSemaphore('dynAMIte.0')
  18.     -> increase opencount to tell dynamite that you are using the
  19.     -> semaphore.  dynamite will remove the semaphore only if opencnt is
  20.     -> 0 at its end
  21.  
  22.     dynasema.opencnt:=dynasema.opencnt+1
  23.   ENDIF
  24.   Permit()
  25.  
  26.   IF dynasema
  27.     WriteF('dynAMIte is started\n')
  28.  
  29.     WriteF('Clients using the semaphore: \d\n',dynasema.opencnt)
  30.  
  31.     WHILE done=FALSE
  32.  
  33.       IF CheckSignal(SIGBREAKF_CTRL_C)
  34.  
  35.         done:=TRUE
  36.  
  37.       ELSE
  38.  
  39.         delay:=TRUE
  40.  
  41.         ObtainSemaphore(dynasema) -> lock it
  42.  
  43.         -> check if dynamite wants to quit
  44.         IF dynasema.quit=1
  45.  
  46.           -> dynamite wants to quit, so we do dynamite a favour
  47.           WriteF('dynAMIte is about to quit...\n')
  48.           done:=TRUE
  49.  
  50.         ELSE
  51.  
  52.           -> if a game is running
  53.           IF dynasema.gamerunning>=GAME_GAME
  54.  
  55.             -> and player is no observer
  56.             IF dynasema.thisplayer<8
  57.  
  58.               delay:=FALSE
  59.  
  60.               ourplayer:=dynasema.player[dynasema.thisplayer]
  61.  
  62.               -> and our player is alive
  63.               IF ourplayer.dead>0
  64.  
  65.                 -> and current game frame has been increased
  66.                 IF dynasema.frames<>oldframe
  67.                   oldframe:=dynasema.frames
  68.  
  69.                   -> do your AI stuff
  70.  
  71.                   dynasema.walk:=Rnd(DIR_UP+1)
  72.  
  73.                 ENDIF
  74.               ENDIF
  75.  
  76.             ENDIF
  77.  
  78.           ENDIF
  79.  
  80.         ENDIF
  81.  
  82.         ReleaseSemaphore(dynasema) -> release it
  83.  
  84.         IF delay
  85.           -> no game is running
  86.           -> do a small delay to let the cpu do other things :(
  87.           Delay(10)
  88.         ENDIF
  89.  
  90.       ENDIF
  91.     ENDWHILE
  92.  
  93.     ObtainSemaphore(dynasema) -> lock it
  94.  
  95.     -> decrease opencount to tell dynamite that you no longer need
  96.     -> the semaphore.
  97.     -> dynamite will remove the semaphore only if opencnt is
  98.     -> 0 at the end
  99.  
  100.     dynasema.opencnt:=dynasema.opencnt-1
  101.  
  102.     ReleaseSemaphore(dynasema) -> release it
  103.  
  104.  
  105.   ELSE -> not found
  106.  
  107.     WriteF('dynAMIte is not running\n')
  108.  
  109.   ENDIF
  110.  
  111. ENDPROC
  112.